package com.example.thinvent.springlife;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MyInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {
    public MyInstantiationAwareBeanPostProcessor(){
        super();
        System.out.println("构造MyInstantiationAwareBeanPostProcessor实例对象");
    }
    /**
     * 方法说明：接口方法、实例化Bean之前调用
     *
     * @param beanClass
     * @param beanName
     * @return java.lang.Object
     * @throws
     * @Author xiaohf
     * @Date 2021/11/16 22:45
     **/
    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        System.out.println(beanName);
        System.out.println("InstantiationAwareBeanPostProcessor调用postProcessBeforeInstantiation");
        return null;
    }

    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        System.out.println(beanName);
        System.out.println("InstantiationAwareBeanPostProcessor调用postProcessAfterInstantiation");
        return true;
    }

    @Override
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
        System.out.println(beanName);
        System.out.println("InstantiationAwareBeanPostProcessor调用postProcessProperties");
        return null;
    }


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println(beanName);
        System.out.println("InstantiationAwareBeanPostProcessor调用postProcessBeforeInitialization");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println(beanName);
        System.out.println("InstantiationAwareBeanPostProcessor调用postProcessAfterInitialization");

        return bean;
    }
}
